<template>

	<view class="content" style="justify-content: center;">
		<image class="logo" mode="widthFix" src="@/static/logo.jpg"></image>
		<text style="margin-top: 48rpx;font-size: 45rpx ;font-weight: bold;">洁净达</text>
		<text class="c6 font28" style="margin-top: 86rpx;">将获得您手机号</text>
		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="authorization">获取手机号登录</button>
		<!-- <view style="color: #aaa ;font-size: 24rpx;margin-top: 20rpx;">
				登录代表您已同意 洁净达用户协议
			</view> -->



		<!-- <woodsPrivacy @cancel="cancel" @agree="agree"></woodsPrivacy> -->

	</view>

</template>

<script>
	import Routine from '@/utils/auth';
	import {
		loginAPI
	} from "@/api/login.js"
	import woodsPrivacy from "@/components/woodsPrivacy/index.vue"
	export default {
		components: {
			woodsPrivacy
		},
		data() {
			return {
				// url:"",
				forwarderId: undefined,
				show: false
			}
		},
		onLoad(option) {
			if (option.forwarderId) {
				this.forwarderId = option.forwarderId
			}
		},
		methods: {
			agree() {

			},
			cancel() {

			},
			async getPhoneNumber(e) {
				const phoneCode = e.detail.code
				if (!e.detail.code) {
					uni.showModal({
						title: '授权失败',
						content: '您已拒绝获取绑定手机号登录授权，可以使用其他手机号验证登录',
						confirmText: '知道了',
						confirmColor: '#3C9CFFFF'
					})
					return;
				}
				// 情况二：允许授权手机号码
				const loginCode = await Routine.getCode()
				const state = e.detail.encryptedData
				uni.showLoading({
					title: '登录中...'
				})
				loginAPI({
					phoneCode,
					loginCode,
					state,
					forwarderId: this.forwarderId
				}).then(res => {
					console.log('res', res)
					/*
					accessToken: "13df1ff4000749d597528fb4ca231475"
					expiresTime: 1721094401825
					openid: "oZrwV7ZPqCZVgXuAsl_BphB8fhs4"
					refreshToken: "440cb559071b466599b3a3b8b53f7c59"
					userId: 259
					*/
					uni.setStorageSync("token", res.data.accessToken)
					uni.setStorageSync("openid", res.data.openid)
					uni.setStorageSync("refreshToken", res.data.refreshToken)
					uni.setStorageSync("userId", res.data.userId)
					uni.hideLoading();
					// if(uni.getStorageSync("lastUrl") && this.forwarderId){
					// uni.reLaunch({
					// 	url:uni.getStorageSync("lastUrl")
					// })
					// }else{
					uni.switchTab({
						url: '/pages/home/home'
					})
					// }

				}).catch(e => {
					console.log('catch', e)
					uni.hideLoading();
				});
			},

		}
	}
</script>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.logo {
		width: 192rpx;
		height: 192rpx;
		/* background-color: red; */
		margin-top: 200rpx;
		border-radius: 50%;
	}

	.authorization {
		background-color: #277EEF;
		margin-top: 20rpx;
		color: #fff;
		font-size: 28rpx;
		width: 560rpx;
		height: 96rpx;
		box-shadow: 0px 8rpx 16rpx 0px rgba(39, 126, 239, 0.3);
		border-radius: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>